﻿function $E(id){ return document.getElementById(id);};
function book_info(bookid,infoid){
	data_book('bookid');
	if(bookid!=0){
		$E('bookid').value = bookid;
		data_info(bookid,'infoid');
	}
	if(infoid!=0){
		data_info(bookid,'infoid');
		$E('infoid').value=infoid;
	}
};

function data_book(div){
	var str = new StringBuffer();
	var val = new StringBuffer();
	for(p in book){
		str.append(book[p][0]+",");
		val.append(p+",");
	}
	init_select(div,str.toString(),val.toString());
};
function data_info(bookid,div){
	var str = new StringBuffer();
	var val = new StringBuffer();
	for(p in bookinfo){
		var o = bookinfo[p];
		if(o[0]==bookid){
			if(o[2]=="0")
				str.append("＋"+o[1]+",");
			else
				str.append("   - "+o[1]+",");
			val.append(p+",");
		}
	}
	init_select(div,str.toString(),val.toString());
};
function init_select(div,strs,vals){
	var s=strs.split(",");
	var v=vals.split(",");
	var o=$E(div);
	o.options.length=1;
	with(o){
		for(i=0;i<v.length;i++){
			if(s[i]!="")options.add(new Option(s[i],v[i]));
		}
	}
};

function book_find(bookid){
	var bookname = "";
	if(bookid!=0)
	for(p in book){
		if(p==bookid){
			bookname = book[p][0];
			break;
		}
	}
	document.write(bookname);
};
function info_find(infoid){
	var bookname = "";
	if(infoid!=0)
	for(p in bookinfo){
		if(p==infoid){
			bookname = bookinfo[p][1];
			break;
		}
	}
	document.write(bookname);
};

//------------------------------------教材首页---------------
function show_jc_grade_new(grade){
	var pic = new StringBuffer();
	var size=0;
	for(p in book){
		if(book[p][2]==grade){
			pic.append("<td align=center><img src='"+book[p][4]+"' width='85' height='100'><br/><br/>");
			pic.append("<a href='/jc_show.html?bookid="+p+"'>"+book[p][0]+"</a><br>&nbsp;<br></td>");
			size++;
			if(size%3==0)pic.append("<tr>");
		}
	}
	$(".subject_all").html("<table width='650' border='0' cellspacing='7' cellpadding='0' class='ui-tabs-panel'><tr><td><br></td></tr><tr>"+pic.toString()+"</tr></table>");
};
function show_jc_subject_new(subject){
	var pic = new StringBuffer();
	var size=0;
	for(p in book){
		if(book[p][3]==subject){
			pic.append("<td align=center><img src='"+book[p][4]+"' width='85' height='100'><br/><br/>");
			pic.append("<a href='/jc_show.html?bookid="+p+"'>"+book[p][0]+"</a><br>&nbsp;<br></td>");
			size++;
			if(size%3==0)pic.append("<tr>");
		}
	}
	$(".subject_all").html("<table width='650' border='0' cellspacing='7' cellpadding='0' class='ui-tabs-panel'><tr><td><br></td></tr><tr>"+pic.toString()+"</tr></table>");
};

function show_jc_one_new(bookid){
	$E("BookName").innerHTML= book[bookid][0];
	$E("BookPic").src= book[bookid][4];
	var pic = new StringBuffer();
	var size=0;
	for(p in bookinfo){
		if(bookinfo[p][0]==bookid && bookinfo[p][2]!=0){
			pic.append("<td style='line-height:150%'><a href='/list_show.html?k=jc&infoid="+p+"&bookid="+bookid+"'>"+bookinfo[p][1]+"</a></td>");
			size++;
			if(size%2==0)pic.append("</tr><tr>");
		}
	}
	if(size==0)
	for(p in bookinfo){
		if(bookinfo[p][0]==bookid){
			pic.append("<td style='line-height:150%'><a href='/list_show.html?k=jc&infoid="+p+"&bookid="+bookid+"'>"+bookinfo[p][1]+"</a></td>");
			size++;
			if(size%2==0)pic.append("</tr><tr>");
		}
	}
	$("#BookRoot").html("<table width='430' border='0' cellspacing='3' cellpadding='0' ><tr>"+pic.toString()+"</tr></table>");

};



//----------------index

function show_jc_new(grade){
	var pic = new StringBuffer();
	var size=0;
	for(p in book){
		if(book[p][2]==grade){
			pic.append("<td align=center><img src='"+book[p][4]+"' width='85' height='100'><br/>");
			pic.append("<a href='/jc_show.html?bookid="+p+"'>"+book[p][0]+"</a><br>&nbsp;<br></td>");
			size++;
			if(size>=6)break;
		}
	}
	$("."+grade).html("<table width='650' border='0' cellspacing='7' cellpadding='0' class='ui-tabs-panel'><tr>"+pic.toString()+"</tr></table>");
};